<?php
namespace app\index\logic;
use think\Db;

class Bookshelf
{
    /*
     * 刷新书架
     * */
    public function refresh($uid, $novelId, $chapterNo)
    {
        $where[] = ['uid', '=', $uid];
        $where[] = ['novel_id', '=', $novelId];

        $record = Db::table('quick_user_bookshelf')->where($where)->field('id')->findOrEmpty();
        if($record)
        {
            Db::table("quick_user_bookshelf")->where("id", $record['id'])->update([
                'chapter_no'    => $chapterNo,
                'read_time'     => date("Y-m-d H:i:s"),
                'delete_time'   => 0,
            ]);
        }else{
            Db::table("quick_user_bookshelf")->insert([
                'uid'           => $uid,
                'novel_id'      => $novelId,
                'chapter_no'    => $chapterNo,
            ]);
        }

    }
}